<?php 
namespace Home\Controller;

use Think\Controller;

class BaseController extends Controller{
    
    public function _initialize(){
        
        if (CONTROLLER_NAME == 'User' && !session('?user')){
            $this->error('请登录',U('Index/index'));die;
        }
        
        // 获取博客栏目
        $cats = M('cat')->order('sort desc,cat_id desc')->select();
        
        // 获取系统信息
        $contact = M('system')->where(array('name'=>array(array('eq','QQ'),array('eq','email'),'or')))->field('value')->select();
        
        // 获取版权信息
        $copyright = M('system')->where(array('name'=>'copyright'))->getField('value');
        
        $blog_M = M('blog');
        
        // 获取文章总数
        $all_blog = $blog_M->count();
        
        // 获取登录状态
        $user = session('user');
        
        $this->assign('user',$user);
        $this->assign('copyright',$copyright);
        $this->assign('cats',$cats);
        
        $this->assign('contact',$contact);
        $this->assign('all_blog',$all_blog);
    }
}

?>